package io.gitee.tianhaoran.chat.common.entity;

import cn.hutool.core.bean.BeanUtil;
import io.gitee.tianhaoran.chat.common.utils.CollectionUtils;

import java.util.List;

/**
 *
 * <p>
 * 作者：沈自在
 **/
public class BeanUtils {

    public static <T> T toBean(Object source, Class<T> targetClass) {
        return BeanUtil.toBean(source, targetClass);
    }

    public static <S, T> List<T> toBean(List<S> source, Class<T> targetType) {
        if (source == null) {
            return null;
        }
        return CollectionUtils.convertList(source, s -> toBean(s, targetType));
    }

    public static  <S, T> PageResult<T> toBean(PageResult<S> source, Class<T> targetType) {
        if (source == null) {
            return null;
        }
        return new PageResult<>(toBean(source.getList(), targetType), source.getTotal());
    }

}